$(function name() {
        let res = localStorage.getItem("Authorization");
        let strings = res.split("."); //截取token，获取载体
        var userinfo = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, "+").replace(/_/g, "/")))));
        $("#name").html(userinfo.sub);
        menu_create(userinfo.sub);
    }
)

function menu_create(username) {
    let res = myAjax(ipAddress()+"/user/g/permission/"+username, {}, "get");
    console.log(res);
    let html = '';
    for (let i = 0; i < res.data.length; i++) {
        if (res.data[i].pid == 0) {
            html += ' <li><a href="javascript:;">\n' +
                '                    <i class="iconfont left-nav-li" lay-tips="' + res.data[i].name + '">&#xe6b8;</i>\n' +
                '                    <cite>' + res.data[i].name + '</cite>\n' +
                '                </a>' +
                '<ul class="sub-menu">'
            let id = res.data[i].id;
            for (let j = 0; j < res.data.length; j++) {
                if (res.data[j].pid == id) {
                    html += ' <li>\n' +
                        '                        <a onclick="xadmin.add_tab(\'' + res.data[j].name + '\',\'' + res.data[j].url + '\')">\n' +
                        '                            <i class="iconfont">&#xe6a7;</i>\n' +
                        '                            <cite>' + res.data[j].name + '</cite></a>\n' +
                        '                    </li>'
                }
            }
            html += '</ul></li>';
        }
    }
    $('#nav').html(html);
}

function logOut() {
    localStorage.clear();
    window.location.reload();
}